<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateOrderCouponExternalSplite extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        return ;
        for ($i = 0; $i <= 99; $i++) {

            $name = str_pad($i, 3, 0, STR_PAD_LEFT);

            Schema::connection("mysqlOrder")
                  ->create('order_coupon_external_' . $name, function (Blueprint $table) use ($name) {

                      $table->unsignedBigInteger('id')->default(0)->comment("主键 id");
                      $table->unsignedInteger("brandId")->default(0)->comment("品牌 Id");
                      $table->unsignedInteger("shopId")->default(0)->comment("店铺 ID");
                      $table->unsignedBigInteger('orderId')->default(0)->comment('订单id');
                      $table->unsignedTinyInteger('extPlatform')->default(0)->comment('外部平台 1美团');
                      $table->string('couponSid')->default('')->comment('券id');
                      $table->string('couponCode', 32)->default('')->comment('核销用券码');
                      $table->string('couponTitle', 32)->default('')->comment('券名称');
                      $table->unsignedTinyInteger('couponType')->default(0)->comment('券类型 1代金券 2套餐券');
                      $table->unsignedInteger('userPay')->default(0)->comment('用户共支付的钱');
                      $table->unsignedInteger('deduction')->default(0)->comment('券共可抵用金额');
                      $table->tinyInteger('couponStatus')->default(0)->comment('核销状态 0默认 1已使用 2已撤销');

                      $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
                      $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
                      $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
                      $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');

                      $table->primary('id', 'idx_id');        // 主键非自增
                      $table->index('shopId', 'shopId_Idx');
                      $table->index('orderId', 'orderId_Idx');
                      $table->index('couponCode', 'couponCode_Idx');
                      $table->index('createdAt', 'createdAt_Idx');

                      $table->collation = 'utf8mb4_general_ci';

                      $table->comment = '订单核销三方平台券明细_' . $name;
                  });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
//        for ($i = 0; $i <= 99; $i++) {
//            $name = str_pad($i, 3, 0, STR_PAD_LEFT);
//            Schema::connection("mysqlOrder")->dropIfExists('order_coupon_external_' . $name);
//        }
    }
}
